package cn.glenn._03vehicle.base.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    private Integer status;
    private String message;
    private Object data;


    public JsonResult(StatusCode statusCode,Object data) {
        this.status = statusCode.getStatus();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    public JsonResult(StatusCode statusCode) {
        this.status = statusCode.getStatus();
        this.message = statusCode.getMessage();
    }

    public static JsonResult success(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
    public static JsonResult success() {
        return success(null);
    }
    public static JsonResult fail() {
        return new JsonResult(StatusCode.OPERATION_FAILED);
    }
    public static JsonResult fail(Object data) {
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }
    public static JsonResult usernameExist(){
        return new JsonResult(StatusCode.USERNAME_EXISTS);
    }
    public static JsonResult usernamePwdError(){
        return new JsonResult(StatusCode.USERNAME_PASSWORD_ERROR);
    }
    public static JsonResult notLogin(){
        return new JsonResult(StatusCode.NOT_LOGIN);
    }
}
